package cc.wanforme.fsync.entity;

import cc.wanforme.fsync.util.DateTimeTool;
import cc.wanforme.st.server.util.FileUtil;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

public class FileInfoVo extends FileInfo{

    private String sizeStr;

    private String createTimeStr;
    private String modifyTimeStr;

    public FileInfoVo(){ }

    public FileInfoVo(FileInfo fileInfo){
        BeanUtils.copyProperties(fileInfo, this);
        this.sizeStr = FileUtil.readableFileSize(fileInfo.getSize());
        if(fileInfo.getCreateTime() > 0) {
            this.createTimeStr = DateTimeTool.format(fileInfo.getCreateTime());
        }
        if(fileInfo.getModifyTime() > 0) {
            this.modifyTimeStr = DateTimeTool.format(fileInfo.getModifyTime());
        }
    }

    public static List<FileInfoVo> listFileVos(String path) {
        List<FileInfo> infos = FileInfo.listFiles(path);

        if(infos != null) {
            List<FileInfoVo> vos = infos.stream().map(FileInfoVo::new).collect(Collectors.toList());
            return vos;
        }
        return null;
    }

    public String getSizeStr() {
        return sizeStr;
    }

    public void setSizeStr(String sizeStr) {
        this.sizeStr = sizeStr;
    }

    public String getCreateTimeStr() {
        return createTimeStr;
    }

    public void setCreateTimeStr(String createTimeStr) {
        this.createTimeStr = createTimeStr;
    }

    public String getModifyTimeStr() {
        return modifyTimeStr;
    }

    public void setModifyTimeStr(String modifyTimeStr) {
        this.modifyTimeStr = modifyTimeStr;
    }

}
